package com.chuanke.ckfamily.action.common;

import java.util.List;

import com.chuanke.ckfamily.service.common.CacheService;
import com.chuanke.ckfamily.service.finance.BillService;
import com.chuanke.ckfamily.service.finance.GainPacketService;
import com.chuanke.ckfamily.service.finance.impl.thread.SynizeCacheToDbThread;
import com.chuanke.ckfamily.service.social.FamilyService;
import com.chuanke.ckfamily.service.social.thread.InitRankThread;
import com.chuanke.ckfamily.service.user.thread.UploadUserMoneyThread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * Created by wangbin on 2017/6/21.
 */
@Controller
@RequestMapping("/api/chator")
public class ApplicationContext implements ApplicationListener<ContextRefreshedEvent> {

	private static final Logger log = LoggerFactory.getLogger(ApplicationContext.class);

    @Autowired
    private CacheService cacheService;

    @Autowired
    private BillService billService;

    @Autowired
    private GainPacketService gainPacketService;
    
    @Autowired
    private FamilyService familyService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
    	if(event.getApplicationContext().getParent() == null){
    	    // root application context 没有parent，他就是老大.
            // 需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。
            log.debug("ApplicationContext.onApplicationEvent start");

            // 启动上传用户资金线程
            new UploadUserMoneyThread(cacheService, billService).start();
            new InitRankThread(familyService).start();
            new SynizeCacheToDbThread(cacheService, gainPacketService).start();
       }
    }

}
